package cn.com.twoke.application.game.mario.core.ecs.entity;

import cn.com.twoke.application.game.mario.core.ecs.component.ColliderComponent;
import cn.com.twoke.application.game.mario.core.ecs.component.Component;
import cn.com.twoke.application.game.mario.core.ecs.component.render.shape.ShapeRenderComponent;
import cn.com.twoke.application.game.mario.game.component.TransfersComponent;
import cn.com.twoke.application.game.mario.game.system.TransfersSystem;

import java.awt.*;

/**
 * 增强
 */
public class EnhancementEntity extends Entity {
   private TransfersSystem transfersSystem;

    public EnhancementEntity(TransfersSystem transfersSystem, int id) {
        super(id);
        this.transfersSystem = transfersSystem;
    }

    @Override
    public <T extends Component> void addComponent(T component) {
        super.addComponent(component);
        if (component instanceof TransfersComponent) {
            transfersSystem.register((TransfersComponent)component);
        }
        if (component instanceof ColliderComponent) {
            this.addComponent(ShapeRenderComponent.builder()
                            .isShow(() -> ColliderComponent.isDebug())
                            .shape(((ColliderComponent) component).shape)
                            .color(new Color(((ColliderComponent) component).hitBoxColor))
                            .fill(false)
                            .index(Integer.MAX_VALUE)
                    .build());
        }
    }


}
